﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WW.Cad.Model;
using WW.Cad.Model.Entities;
using WW.Cad.Model.Tables;
using WW;
using WW.Actions;
using WW.Cad.Drawing;
using WW.Cad.Drawing.GDI;
using WW.Drawing;
using WW.Math;
using WW.Math.Geometry;

namespace StuertzDatenbank
{
    
    class DrawingHandler
    {
        private Sprachfile sprachfile;

        public DrawingHandler()
        {

            sprachfile = new Sprachfile();
        }


        internal Profil zuordnen(string Typ, String Name, Profil profil, int i, DxfModel model)
        {

            LayerExtractor layerex = new LayerExtractor();
            DxfModel Model = new DxfModel();
           



            layerex.Run(model, model.Layers[i]);
                Model = layerex.model;

            if (Typ == sprachfile.Zeichnung)
            {
                profil.setBezeichnung(Name);
                profil.setZeichnung(Model);
               
            }
            else if (Typ == sprachfile.Bearbeitung)
            {
                Bearbeitungen a = new Bearbeitungen(-1);
                a.setBearbeitungsname(Name);
                a.setLayer(Model);
                profil.getBearbeitungen().Add(a);
                
            }
            else if (Typ ==sprachfile.Füllmaterial)
            { 
                StuertzDatenbank.Fuellmaterial a = new Fuellmaterial(-1);
                a.setFuellmaterial(Name);
                a.setLayer(Model);
                profil.getFuellmaterial().Add(a);

            }
            else if (Typ == sprachfile.Dichtung)
            {
                StuertzDatenbank.Dichtung a = new Dichtung(-1);
               
                a.setDichtung(Name);
                a.setLayer(Model);
                profil.getDichtung().Add(a);
                
            }

           
            return profil;
        }
        public DxfModel fuisonmodel(DxfModel amodel, DxfModel bmodel,String bmodelname ,  Point3D position)
        {
            if (position == null)
            {
                position.X = 0;
                position.Y = 0;
                position.Z = 0;
            }


            DxfBlock result = new DxfBlock();
            result.Name = bmodelname;

            CloneContext cT = new CloneContext(amodel, ReferenceResolutionType.CloneMissing);
            cT.RenameClashingBlocks = true;

            foreach (DxfEntity sourceEntity in bmodel.Entities)
            {
                DxfEntity clonedEntity = (DxfEntity)sourceEntity.Clone(cT);
                result.Entities.Add(clonedEntity);
            }

            cT.ResolveReferences();

            amodel.Blocks.Add(result);
            amodel.Entities.Add(new DxfInsert(result, position));

            bmodel.Dispose();

            return amodel;

        }

       
    }
}
